<?php

class bobSplashScreen extends GtkWindow {
	
	public $file;
	public $x,$y;
	public $move;

	public function __construct($move = true) {
		parent::__construct();
		$this->file = "{$GLOBALS['PATH_IMAGES']}/splash.png";
		$this->doMove = $move;
		
		$this->image = GtkImage::new_from_file($this->file);
		
		$this->set_title(sprintf('Loading %s v%s',PROGRAM,VERSION));
		$this->set_position(Gtk::WIN_POS_CENTER);
		$this->set_skip_taskbar_hint(true);
		$this->set_keep_above(true);
		$this->set_decorated(false);
		$this->set_type_hint(Gdk::WINDOW_TYPE_HINT_SPLASHSCREEN);

		Gtk::timeout_add(500,array($this,'checkAppStatus'));

		$this->add($this->image);
		$this->show_all();

		if($twotwelve = method_exists($this,'set_opacity')) {
			$this->set_opacity($this->opacity = 0);
		}		

		bob::runUI();
		
		if($twotwelve) {
			if($move) {
				list($this->x,$this->y) = $this->window->get_position();
				$this->move($this->x -= 24, $this->y -= 24);
			}
			
			Gtk::timeout_add(20,array($this,'runOpacity'),true);
			Gtk::main();
		}
		// ^ get the splash screen stuck owning the application while it
		// fades in woot :D
			
		return;
	}
	
	public function runOpacity($up = true) {
		/*//. this is my cool splash screen slide/fade animation. it
		  ../ should only be run if Gtk 2.12 or higher. .//*/
	
		if($up) {
			$this->opacity += 0.05;
		} else {
			$this->opacity -= 0.05;
		}
		
		$continue = true;
	
		if($up && $this->opacity >= 1) {
			$this->opacity = 1;
			$continue = false;
		} if(!$up && $this->opacity <= 0) {
			$this->opacity = 0;
			$continue = false;
		}
		
		$this->set_opacity($this->opacity);
		
		if($this->doMove) {
			$this->move(
				$this->x += ((1 - $this->opacity)*3),
				$this->y += ((1 - $this->opacity)*3)
			);
		}
		
		bob::runUI();
		
		if(!$continue) {
			Gtk::main_quit();
			// ^ unstucking the application XD
		}
		
		return $continue;
	}
	
	public function checkAppStatus() {
		if(bob::$run == 1) {
			Gtk::timeout_add(100,array('bob','destroySplash'));
			return false;
		} else {
			return true;
		}
	}
}

?>